def write_diary():
    file = open("E:\\Python\\code\\pycharm\\python_base\\my_package\\diaries.txt", mode='a', encoding='utf-8')
    date = input("请输入日期：")
    content = input("请输入内容：")
    file.write('diarySeparator\n')
    file.write(date + '\n')
    file.write(content + '\n')
    file.close()


def read_diary(date):
    file = open('E:\\Python\\code\\pycharm\\python_base\\my_package\\diaries.txt', mode='r', encoding='utf-8')
    content = file.read()
    if date != '-1':  # 读取指定日期
        content_list = content.split('diarySeparator\n')
        flag = False
        for i in content_list:
            if i[:8] == date:
                print(i)
                flag = True
                break
        if not flag:
            print("查不到相关日记")
    else:  # 读取全部
        content = content.replace('diarySeparator\n', '')
        print(content)
    file.close()

def menu():
    print("*" * 30)
    print('''欢饮使用日记系统，请按以下提示操作！
    1.写日记
    2.读日记
    3.退出系统''')
    print("*" * 30)
    while True:
        op = input("请输入操作指令：")
        if op == '1':
            write_diary()
            print('日记保存成功！')
        elif op == '2':
            date = input("请输入日期(读取全部输入-1):")
            read_diary(date)
        elif op == '3':
            print("感谢使用本系统！")
            break
        else:
            print("请重新输入！")
